package com.dhecp.project.system.controller;

import com.dhecp.common.annotation.Log;
import com.dhecp.common.annotation.RepeatSubmit;
import com.dhecp.common.core.controller.BaseController;
import com.dhecp.common.core.domain.AjaxResult;
import com.dhecp.common.core.page.TableDataInfo;
import com.dhecp.common.enums.BusinessType;
import com.dhecp.project.system.domain.SysHardWareRegisterInfo;
import com.dhecp.project.system.service.SysHardWareRegisterInfoService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;

/**
 * @ClassName SysHardWareRegisterInfoController
 * @Description TODO
 * @Author alula
 * @Date 2020-07-21 16:25
 */
@Controller
@RequestMapping("/system/hardwareauth")
public class SysHardWareRegisterInfoController extends BaseController {

    private String prefix = "system/hardwareauth";

    @Autowired
    private SysHardWareRegisterInfoService sysHardWareRegisterInfoService;

    @GetMapping()
    public String hardwareauth()
    {
        return prefix + "/hardwareauth";
    }

    @RequiresPermissions("system:hardwareauth:list")
    @RequestMapping("/reglist")
    @ResponseBody
    public TableDataInfo regList(@RequestParam Map<String, Object> params)
    {
        startPage();
        List<SysHardWareRegisterInfo> list = sysHardWareRegisterInfoService.querySysHardWareRegisterInfoList(params);
        return getDataTable(list);
    }

    @RequiresPermissions("system:hardwareauth:list")
    @RequestMapping("/unreglist")
    @ResponseBody
    public TableDataInfo unRegList(@RequestParam Map<String, Object> params)
    {
        startPage();
        List<SysHardWareRegisterInfo> list = sysHardWareRegisterInfoService.querySysHardWareUnRegisterInfoList(params);
        return getDataTable(list);
    }

    @Log(title = "电脑授权", businessType = BusinessType.UPDATE)
    @RequiresPermissions("system:hardwareauth:edit")
    @PostMapping("/authpost")
    @ResponseBody
    @RepeatSubmit
    public AjaxResult authSave(String unId)
    {
        AjaxResult ajaxResult = new AjaxResult();
        try {
            ajaxResult= sysHardWareRegisterInfoService.insertSysHardWareRegisterInfo(unId);
        }catch (Exception e) {
            ajaxResult = AjaxResult.error(this.getExceptionMessage(e));
        }
        return ajaxResult;
    }


    @Log(title = "电脑取消授权删除", businessType = BusinessType.DELETE)
    @RequiresPermissions("system:hardwareauth:delete")
    @RequestMapping("/regdelete")
    @ResponseBody
    public AjaxResult regDelete(@RequestParam("id") String id) {
        AjaxResult ajaxResult = new AjaxResult();
        try {
            ajaxResult = sysHardWareRegisterInfoService.deleteSysHardWareRegisterInfo(id);
            return ajaxResult;
        }
        catch (Exception e) {
            return AjaxResult.error(this.getExceptionMessage(e));
        }
    }

    @Log(title = "电脑待授权删除", businessType = BusinessType.DELETE)
    @RequiresPermissions("system:hardwareauth:delete")
    @RequestMapping("/unregdelete")
    @ResponseBody
    public AjaxResult unRegDelete(@RequestParam("id") String id) {
        AjaxResult ajaxResult = new AjaxResult();
        try {
            ajaxResult = sysHardWareRegisterInfoService.deleteSysHardWareUnRegisterInfo(id);
            return ajaxResult;
        }
        catch (Exception e) {
            return AjaxResult.error(this.getExceptionMessage(e));
        }
    }
}
